package cn.edu.jnu.entity;

import cn.edu.jnu.GameWin;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

/**
 * 功能：
 * 作者：陈爱国
 * 日期：2024/8/10 11:54
 */
public class PlaneObj extends GameObj {
    public PlaneObj() {
        super();
    }

    public PlaneObj(Image img, int x, int y, double speed) {
        super(img, x, y, speed);
    }

    public PlaneObj(Image img, int x, int y, int width, int height, double speed, GameWin frame) {
        super(img, x, y, width, height, speed, frame);

        // 添加鼠标事件
        this.frame.addMouseMotionListener(new MouseAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                PlaneObj.super.x = e.getX() - 11;
                PlaneObj.super.y = e.getY() - 16;
            }
        });
    }

    @Override
    public void paintSelf(Graphics gImage) {
        super.paintSelf(gImage);

        // 我方飞机与敌方boss的碰撞检测
        if(this.frame.bossObj!=null && this.getRect().intersects(this.frame.bossObj.getRect())){
            GameWin.state = 3;
        }
    }

    @Override
    public Rectangle getRect() {
        return super.getRect();
    }
}
